{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "34ddc58f",
   "metadata": {},
   "source": [
    "-----\n",
    "* 时间：2022/10/17 week9\n",
    "* 记录人：杨韵桦"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37b25c96",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 用户输入\n",
    "> 2. 文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8160f57b",
   "metadata": {},
   "source": [
    "# 1.用户输入\n",
    "* input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ea6308a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admin\n",
      "密码:123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "91e33669",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e29aaede",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：wpd\n",
      "账号不存在或密码不正确！请重新输入！\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1 增加判断\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "\n",
    "username = input(\"账号：\")\n",
    "password = input(\"密码：\")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and  password01 == password:\n",
    "    print(\"登陆成功~欢迎\"+user01)\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确！请重新输入！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fa2dcd54",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：fe\n",
      "账号不存在或密码不正确！请重新输入！您还有2次尝试的机会\n",
      "账号：admin\n",
      "密码：wjww\n",
      "账号不存在或密码不正确！请重新输入！您还有1次尝试的机会\n",
      "账号：admin\n",
      "密码：22\n",
      "账号不存在或密码不正确！请1小时候再来尝试\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ 5分钟，加油~ for + range()  10点35分 \n",
    "\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时候再来尝试\")\n",
    "        \n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2634278f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "for i in range(3,0,-1):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "723b6e79",
   "metadata": {},
   "source": [
    "## 2. 字符串的格式化输出\n",
    "\n",
    ">1. 字符串拼接\n",
    ">2. 占位符\n",
    ">3. 格式化输出的方法： format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e5ed179b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区: 深圳\n",
      "工作:产品经理助理\n",
      "年龄: 22\n",
      "期待薪资: 10k/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作:\")\n",
    "age = input(\"年龄: \")\n",
    "salary = input(\"期待薪资: \")\n",
    "\n",
    "info=  '''--------------INFO'''+ name + ''' --------'''\n",
    "地区:'''+ region + '''\n",
    "工作:'''+ job + '''\n",
    "年龄:''' + age + '''\n",
    "薪资期待:''' + salary + '''\n",
    "# 好麻烦好容易出错    \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4e06b46f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO李华 ----------\n",
      "地区:深圳\n",
      "工作:python web开发\n",
      "年龄：:22\n",
      "薪资期待:18k/月\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09fa3ddb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户的信息输入（完善信息） : 占位符 s%\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s --------\n",
    "地区：%s \n",
    "工作：%s \n",
    "年龄：%s\n",
    "薪资期待：%s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "549781d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称: 李华\n",
      "地区: 深圳\n",
      "工作: python web开发\n",
      "年龄: 22\n",
      "期待薪资:18k/月\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'into' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn [1], line 13\u001b[0m\n\u001b[0;32m      6\u001b[0m salary  \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m期待薪资:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      8\u001b[0m info \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'''\u001b[39m\u001b[38;5;124m---------INFO\u001b[39m\u001b[38;5;132;01m{昵称}\u001b[39;00m\u001b[38;5;124m ----------\u001b[39m\n\u001b[0;32m      9\u001b[0m \u001b[38;5;124m地区:\u001b[39m\u001b[38;5;132;01m{地区}\u001b[39;00m\n\u001b[0;32m     10\u001b[0m \u001b[38;5;124m工作:\u001b[39m\u001b[38;5;132;01m{工作职位}\u001b[39;00m\n\u001b[0;32m     11\u001b[0m \u001b[38;5;124m年龄：:\u001b[39m\u001b[38;5;132;01m{年龄}\u001b[39;00m\n\u001b[0;32m     12\u001b[0m \u001b[38;5;124m薪资期待:\u001b[39m\u001b[38;5;132;01m{薪资}\u001b[39;00m\u001b[38;5;124m'''\u001b[39m\u001b[38;5;241m.\u001b[39mformat(工作职位\u001b[38;5;241m=\u001b[39mjob,薪资\u001b[38;5;241m=\u001b[39msalary,昵称\u001b[38;5;241m=\u001b[39mname,年龄\u001b[38;5;241m=\u001b[39mage,地区\u001b[38;5;241m=\u001b[39mregion)\n\u001b[1;32m---> 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(into)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'into' is not defined"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入 （完善信息）: format()\n",
    "name = input(\"昵称: \")\n",
    "region = input(\"地区: \")\n",
    "job = input(\"工作: \")\n",
    "age = input(\"年龄: \")\n",
    "salary  = input(\"期待薪资:\")\n",
    " \n",
    "info = '''---------INFO{昵称} ----------\n",
    "地区:{地区}\n",
    "工作:{工作职位}\n",
    "年龄：:{年龄}\n",
    "薪资期待:{薪资}'''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(into)\n",
    "# 书写规范，字符串中的字段 一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b621b18",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
